function save() {
	// save form values to Chrome's localStorage
	localStorage["username"] = $("#username").val();
	localStorage["password"] = $("#password").val();
	localStorage["pagecount"] = $("#pagecount").val();
	localStorage["opennewtab"] = $("#opennewtab").val();
	localStorage["theme"] = $("#themes").val();
	localStorage["readAnimation"] = $("#readAnimation").val();
	localStorage["autoSuggest"] = $("#autoSuggest").val();
	
	chrome.extension.getBackgroundPage().checkBadge();
	
	setTheme();
	
	// test username/password
	// returns status message
	auth(function(request, status) {
		if (status != "success")
			setMessage("Username/password incorrect, please try again.", "error").delay(3000).fadeOut("slow");			
		else
			setMessage("Account credentials successfully authenticated! Check out your <a href=\"list.html\">new page</a>.", "").delay(10000).fadeOut("slow");
	});
	
	//$("#status").html("Options have been successfully saved!").show("slow");
}

$(function() {
	if (!localStorage.theme) localStorage.theme = "new";
	$("link.theme").attr("href", "../css/themes/" + localStorage.theme + ".css");

	// if username exists in localStorage, fill in the input
	if (localStorage["username"] != undefined && localStorage["username"] != "") {
		$("#username").val(localStorage["username"]);
	}
	
	// if password exists in localStorage, fill in the input
	if (localStorage["password"] != undefined && localStorage["password"] != "") {
		$("#password").val(localStorage["password"]);
	}
	
	// if pagecount exists in localStorage, fill in the input
	// otherwise show the default of 16
	if (localStorage["pagecount"] != undefined && localStorage["pagecount"] != "") {
		$("#pagecount").val(localStorage["pagecount"]);
	} else
		$("#pagecount").val(16);
		
	// if opennewtab exists in localStorage, fill in the input
	if (localStorage["opennewtab"] != undefined && localStorage["opennewtab"] != "") {
		$("#opennewtab").val(localStorage["opennewtab"]);
	}
	
	// if theme exists in localStorage, select in the list
	if (localStorage["theme"] != undefined && localStorage["theme"] != "") {
		$("#themes").val(localStorage["theme"]);
	}
	
	// if readAnimation exists in localStorage, select in the list
	if (localStorage["readAnimation"] != undefined && localStorage["readAnimation"] != "") {
		$("#readAnimation").val(localStorage["readAnimation"]);
	}
	
	// if autoSuggest exists in localStorage, select in the list
	if (localStorage["autoSuggest"] != undefined && localStorage["autoSuggest"] != "") {
		$("#autoSuggest").val(localStorage["autoSuggest"]);
	}
	
	/*
	$("button").hover(
		function() { $(this).removeClass("ui-state-default").addClass("ui-state-hover"); }, 
		function() { $(this).removeClass("ui-state-hover").addClass("ui-state-default"); }
	);
	*/
});

function showHelp(section) {
	$("#help-" + section).dialog( { 
		draggable: false,
		resizable: false,
		width: "550px",
		modal: true,
		buttons: {
			"Close": function() { $(this).dialog("close"); }
		}
	} );
}